package com.edu.method;

public class ThreadMethod02 {
    public static void main(String[] args) throws InterruptedException {
        T2 t2 = new T2();
        t2.start();

        for (int i = 1; i <= 10; i++) {
            try {
                System.out.println(Thread.currentThread().getName() + "吃包子" + i);
                Thread.sleep(1000);
            } catch (InterruptedException e) {

            }
            if (i == 5) {
                System.out.println("主线程" + Thread.currentThread().getName() + "让子线程+" + t2.getName() + "先吃");
                //join,插队
//                t2.join();// 这里相当于让t2线程先执行完毕

                Thread.yield();//礼让，不一定成功
                System.out.println("线程" + t2.getName() + "吃完了，让线程" + Thread.currentThread().getName() + "接着吃");
            }
        }
    }
}


class T2 extends Thread {
    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            try {
                System.out.println(Thread.currentThread().getName() + "吃包子" + i);
                Thread.sleep(1000);
            } catch (InterruptedException e) {

            }
        }
    }
}
